#!/usr/bin/env python
# -*- coding: utf-8 -*-
# datetime: 3/12/2023 下午1:01
# Author: name
# File: function_model.py
# ide: PyCharm
# description: 函数相关数据库模型


from datetime import datetime
from typing import List

from pydantic import BaseModel
from tortoise import fields
from tortoise.models import Model


class FunctionModel(Model):
    id = fields.IntField(pk=True, description="主键")
    zh_name = fields.CharField(max_length=255, description="中文名称")
    en_name = fields.CharField(max_length=255, description="函数方法名称")
    content = fields.TextField(max_length=20480, description="函数脚本内容")
    params = fields.CharField(max_length=255, description="函数调试参数")
    created_at = fields.CharField(max_length=255)
    updated_at = fields.CharField(max_length=255)

    class Meta:
        table = "functions"


class FunctionIn(BaseModel):
    zh_name: str
    en_name: str
    content: str
    params: str = None


class FunctionOut(BaseModel):
    id: int
    zh_name: str
    en_name: str
    content: str
    params: str
    created_at: str
    updated_at: str


class FunctionPage(BaseModel):
    total: int
    page_size: int
    current_page: int
    search_key: str = None
    results: List[FunctionOut]
